/* 可以获取openlayers所有的图层; */
function getLayers(map) {
    return map.getLayers().getArray()
}
/* 根据图层的title属性获取对应的图层 */
function getLayerByTitle({
    map,
    title
}) {
    /* 1、将所有的图层获取 */
    let layers = map.getLayers().getArray()
    /* 2、获取title值对应的图层 find */
    let target = layers.find(item => item.get("title") == title)
    return target;

}
/* 封装点的样式 */
function setPntStyle({
    radius = 15,
    color = "red"
}) {
    return new ol.style.Style({
        image: new ol.style.Circle({
            radius,
            fill: new ol.style.Fill({
                color
            })
        })
    })
}
/* 封装线的样式 */
function setLineStyle({
    color = "red",
    width = 5
}) {
    return new ol.style.Style({
        stroke: new ol.style.Stroke({
            width,
            color
        })
    })
}
/* 设置区域样式 */
function setAreaStyle({
    strokeColor = "rgba(255, 255, 0, 0.5)",
    fillColor = "rgba(255, 255, 0, 0.5)",
    fillOpacity = 0.5
}) {
    return new ol.style.Style({
        stroke: new ol.style.Stroke({
            color: strokeColor,
            width: 2
        }),
        fill: new ol.style.Fill({
            color: fillColor,
            opacity: fillOpacity
        })
    })
}

export{
    getLayers,
    getLayerByTitle,
    setPntStyle,
    setLineStyle,
    setAreaStyle
}